﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace LCARSLibrary.Controls
{
    public class Panel : LCARSBase
    {
        #region fields

        Orientation orientation;

        int columnWidth;
        int rowHeight;

        #endregion

        #region properties

        [Browsable(true), Category("LCARS"), DefaultValue(110)]
        public int ColumnWidth
        {
            get
            {
                return columnWidth;
            }
            set
            {
                columnWidth = value;
                base.Invalidate();
            }
        }

        [Browsable(true), Category("LCARS"), DefaultValue(10)]
        public int RowHeight
        {
            get
            {
                return rowHeight;
            }
            set
            {
                rowHeight = value;
                base.Invalidate();
            }
        }

        [Browsable(true), Category("LCARS"), DefaultValue(typeof(Orientation), "TopLeft")]
        public Orientation Orientation
        {
            get
            {
                return orientation;
            }
            set
            {
                orientation = value;
                base.Invalidate();
            }
        }

        [Browsable(false)]
        public override Color TextColor
        {
            get { return base.TextColor; }
        }

        #endregion

        public Panel()
        {
            base.DoubleBuffered = true;
            base.Size = new Size(400, 320);

            base.BackColor = Color.Black;

            columnWidth = 110;
            rowHeight = 10;
            orientation = Orientation.TopLeft;
            this.Margin = new Padding(2);
        }


        private void CreatePanel(Graphics g, int x, int y, int width, int height, int colWidth, int rowHeight)
        {
            int radiusIn = 40;
            //war mal 140, auf 80 geändert
            int radiusExt = 80;

            g.SmoothingMode = SmoothingMode.AntiAlias;

            using (GraphicsPath pathFG = new GraphicsPath())
            using (GraphicsPath pathBG = new GraphicsPath())
            {
                switch (orientation)
                {
                    case Orientation.TopLeft:
                        {
                            RoundedRectangle.CreateRoundRectPath(pathFG, x, y, width, height, radiusExt, Corner.TopLeft);
                            RoundedRectangle.CreateRoundRectPath(pathBG, x - 1 + colWidth, y - 1 + rowHeight, width + 1, height + 1, radiusIn, Corner.TopLeft);
                            break;
                        }
                    case Orientation.TopRight:
                        {
                            RoundedRectangle.CreateRoundRectPath(pathFG, x, y, width, height, radiusExt, Corner.TopRight);
                            RoundedRectangle.CreateRoundRectPath(pathBG, x - 1, y - 1 + rowHeight, width + 1 - colWidth, height + 1, radiusIn, Corner.TopRight);
                            break;
                        }
                    case Orientation.BottomLeft:
                        {
                            RoundedRectangle.CreateRoundRectPath(pathFG, x, y, width, height, radiusExt, Corner.BottomLeft);
                            RoundedRectangle.CreateRoundRectPath(pathBG, x - 1 + colWidth, y - 1, width + 1, height + 1 - rowHeight, radiusIn, Corner.BottomLeft);
                            break;
                        }
                    case Orientation.BottomRight:
                        {
                            RoundedRectangle.CreateRoundRectPath(pathFG, x, y, width, height, radiusExt, Corner.BottomRight);
                            RoundedRectangle.CreateRoundRectPath(pathBG, x - 1, y - 1, width + 1 - colWidth, height + 1 - rowHeight, radiusIn, Corner.BottomRight);
                            break;
                        }
                }


                using (SolidBrush brushFG = new SolidBrush(this.Color))
                using (SolidBrush brushBG = new SolidBrush(this.BackColor))
                {
                    g.FillPath(brushFG, pathFG);
                    g.FillPath(brushBG, pathBG);
                }
            }
        }


        protected override void OnSizeChanged(EventArgs e)
        {
            base.Invalidate();
            base.OnSizeChanged(e);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            CreatePanel(e.Graphics, 0, 0, base.Width, base.Height, columnWidth, rowHeight);
        }

        #region Not available for LCARS_Border

        [Browsable(false)]
        public override Image BackgroundImage
        {
            get
            {
                return base.BackgroundImage;
            }
            set
            {
            }
        }

        [Browsable(false)]
        public override ImageLayout BackgroundImageLayout
        {
            get
            {
                return base.BackgroundImageLayout;
            }
            set
            {
            }
        }

        #endregion
    }
}
